<template>
  <view class="content top">
    <!-- 首页导航栏 -->
    <view class='flex tab'>
      <view class="search slanted-border">
        <text class="text-white  cuIcon-search icon"></text>
        <text class="text-white">搜一搜</text>
      </view>
      <view class="title text-bold">派单</view>
    </view>

    <!-- 游戏种类栏 -->
    <view class="text-area">
      <scroll-view scroll-x class="scroll-x">
        <view v-for="(item,index) in tabData" :key="item.id" @click="tabIndex = item.id">
          <view v-if="tabIndex == item.id" class="tab-i" >
            <text class="tab-i-text">{{item.name}}</text>
            <image :src="baseUrl() + item.icon" referrerpolicy="no-referrer" />
          </view>
          <view v-else>
            <text class="tab-i-text" style="padding: 4px 12px 4px 12px;">{{item.name}}</text>
          </view>
        </view>
      </scroll-view>
    </view>

    <!-- 筛选条件-->
    <view class="search-i flex-row">
      <image
          class="image_2"
          referrerpolicy="no-referrer"
          src="https://a-1319987989.cos.ap-guangzhou.myqcloud.com/images/SketchPngdafe2c0f5c9a60a263283599036051774c01357e4eeae8ca5eae2f170b1ad353"
      />
      <view class="flex-row">
        <view class="flex-row"><text>最新发布</text><image referrerpolicy="no-referrer" src="https://a-1319987989.cos.ap-guangzhou.myqcloud.com/images/SketchPng52335ee9a88e88d84edab3c92a7912bcceafca2ee70a09d638098502e99293d9"/></view>
        <view class="flex-row"><text>价格最高</text><image referrerpolicy="no-referrer" src="https://a-1319987989.cos.ap-guangzhou.myqcloud.com/images/SketchPng52335ee9a88e88d84edab3c92a7912bcceafca2ee70a09d638098502e99293d9"/></view>
        <view class="flex-row"><text>信誉工作室</text><image referrerpolicy="no-referrer" src="https://a-1319987989.cos.ap-guangzhou.myqcloud.com/images/SketchPng52335ee9a88e88d84edab3c92a7912bcceafca2ee70a09d638098502e99293d9"/></view>
      </view>
    </view>

    <!-- 订单卡片展示 -->
    <view class="order-card">
      <mescroll-uni ref="mescrollRef" :top="0" :fixed="false" @init="mescrollInit" @down="downCallback"
                    :down="downOption" :up="upOption" @up="upCallback">
        <order-card :list="tableData"/>
      </mescroll-uni>
    </view>
  </view>
</template>

<script>

import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
import {listOrder} from "@/api/attend/order";
import {listGame} from "@/api/attend/game";
import {baseUrl} from "@/config";
import OrderCard from "@/components/index/order-card.vue";

export default {
  components: {OrderCard},
  mixins: [MescrollMixin],
  data() {
    return {
      tabIndex: 1,
      TabCur: 0,//游戏种类栏index
      highLowCur: 0,//价格高低栏index
      scrollLeft: 0,
      tabData:[],//游戏种类栏数据

      screenInfo:{
        createTime:[],
        gameId: null,
        sort: [{key:'', sort:0},{key:'', sort:0},{key:'', sort:0}]
      },
      tableData: [],
      downOption: {

      },
      upOption: {
        page: {
          num: 0,
          size: 10 // 每页数据的数量,默认10
        },
        noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
        empty: {
          tip: '~ 空空如也 ~'
        }
      }
    };
  },
  watch: {
    tabIndex(i) {
      let _that = this
      _that.accessList = []
      _that.mescroll.resetUpScroll()
    }
  },
  onLoad(opt) {
    let _that = this
    _that.listGame()
  },
  onShow(){
    let _that = this
    _that.listGame()
    if(_that.mescroll)_that.mescroll.resetUpScroll()
  },
  methods: {
    baseUrl() {
      return baseUrl
    },
    changeTab(index){
      this.tabIndex = index;
    },
    listGame(){
      let _that = this
      let params = {
        pageNo: 1,
        pageSize: 10,
        gameId: _that.tabIndex
      }
      listGame(params).then((res) => {
        _that.tabData = res.rows
      })
    },
    /*下拉刷新的回调 */
    downCallback() {
      this.mescroll.resetUpScroll()
    },
    /* 上拉翻页 */
    upCallback(page) {
      let _that = this
      let data = {
        pageNo: page.num,
        pageSize: page.size,
        ..._that.screenInfo,
      }

      listOrder(data).then((res) => {
        console.log(res, 'res')
        _that.mescroll.endSuccess(res.rows.length);
        if (page.num == 1) _that.tableData = [];
        _that.tableData = _that.tableData.concat(res.rows); //追加新数据
      }).catch(err => {
        _that.mescroll.endErr();
      })
    },
    btnNav(url) {
      url && app.btnNav(url)
    },


  },
}
</script>

<style lang='scss'>
.content {
  display: flex;
  flex-direction: column;
}
.top{
  width: 100%;
  height: 100%;
  padding-top: 44px;
  background: #F4F2FB url("https://a-1319987989.cos.ap-guangzhou.myqcloud.com/images/db1c8086deb34fa29f4bf890a515d2de_mergeImage.png") no-repeat;
  background-size: 100%;

}
.tab{
  margin: 10px 0;
  .search{
    text-align: center;
    .icon{
      margin-right: 4rpx;
    }
  }
  .title{
    text-align: left;
    margin:0rpx 80rpx;
    padding: 2px 0rpx;
    font-weight: 600;
    font-size: 36rpx;
    color: #22004B;
  }
  .slanted-border {
    width: 192rpx;
    height: 56rpx;
    background-color:rgb(146, 148, 211);
    border-radius: 8rpx;
    border: 1px solid #ccc;
    border-width: 1px 0; /* 设置上边框和下边框的宽度为1像素，左右边框宽度为0 */
    transform: skewX(-10deg); /* 向左倾斜10度 */
    margin:0rpx 32rpx;
    padding: 8rpx 36rpx;
  }
}





.btn{
  position: fixed;
  bottom: 7%;
  right: 5%;

}
.bot-padding{
  padding-bottom: 20upx;
}

.text-area {
  display: flex;
  .cu-item{
    color:#22004B;
    font-size: 28rpx;
  }

}
.price{
  display: flex;
  font-size: 12px
}
.price-item{
  margin: 0 30upx;
}
.title-item{
  margin: 0 15upx;
  flex: 9;
}
.item{
  border-bottom: 1px solid #ccc;
  display: flex;

}
.imgSize{
  width: 30px;
  height: 30px;
  flex: 1;
}
.price-icon{
  margin-left: 10upx;
}
.card-item{
  margin: 20upx;
}

.title {
  font-size: 36rpx;
  color: #8f8f94;
}


.scroll-x{
  width: 100%;
  // 设置 white-space 属性为 nowrap，这会导致文本不换行，适合横向滚动的布局
  white-space: nowrap;
  padding: 0px 16px 0px 16px;
  view{
    // 设置 display 属性为 inline-block，这会使元素以内联块级元素的方式显示，可以在同一行内显示多个元素
    display: inline-block;
  }
}

.tab-i{
  background: url("https://a-1319987989.cos.ap-guangzhou.myqcloud.com/images/SketchPng7e0eb6af23391fdaf51e217dce4c9ce8715148e7bb848f246831d59686b96a81")
  100% no-repeat;
  background-size: 100% 100%;
  position: relative;
  padding: 4px 14px 4px 44px;
  image{
      position: absolute;
      left: 0;
      top: -6px;
      width: 40px;
      height: 40px;
  }
}
.tab-i-text{
  overflow-wrap: break-word;
  color: rgba(34, 0, 75, 1);
  font-size: 14px;
  font-family: PingFangSC-Semibold;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  line-height: 20px;
}

.search-i{
  width: 347px;
  margin: 18px 12px 0 16px;
  image{
    width: 55px;
    height: 13px;
    margin: 4px 0 5px 0;
  }
  view{
    width: 249px;
    height: 22px;
    justify-content: space-between;
    view{
      background-color: rgba(255, 255, 255, 0.45);
      border-radius: 12px;
      width: 82px;
      margin-right: 4px;
      padding: 3px 8px 3px 8px;
      text{
        width: 55px;
        overflow-wrap: break-word;
        color: rgba(34, 0, 75, 0.65);
        font-size: 11px;
        font-weight: normal;
        text-align: right;
        white-space: nowrap;
        line-height: 16px;
      }
      image{
        width: 10px;
        height: 10px;
        margin: 3px 0 3px 0;
      }
    }
  }
}
</style>
